package com.zhou.basics.common.exception2;

import com.zhou.basics.common.core.Result;
import com.zhou.basics.common.exception.ServiceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @ProjectName: tsqingcheng
 * @ClassName: GlobalExceptionHandler
 * @Time: 2020/2/27
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = NullPointerException.class)
    public Result aa(HttpServletRequest req, NullPointerException e){
        System.out.println("++++");
        return new Result(10,"npe:"+e.getMessage()+" "+e.toString());
    }

    @ExceptionHandler(value = Exception.class)
    public Result cc(HttpServletRequest req, Exception e){
        System.out.println("++++");
        return new Result(11,"e:"+e.getMessage()+" "+e.toString());
    }

    @ExceptionHandler(value = IndexOutOfBoundsException.class)
    public Result bb(HttpServletRequest req, IndexOutOfBoundsException e){
        System.out.println("++++");
        return new Result(12,"ioobe:"+e.getMessage()+" "+e.toString());
    }


    @ExceptionHandler(value = ServiceException.class)
    public Result dd(HttpServletRequest req, ServiceException e){
        System.out.println("++++");
        return new Result(13,"se:"+e.getMessage()+" "+e.toString());
    }

}
